package redes;

import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.JTable;

/**
 *
 * @author Thiago
 */
public class View extends javax.swing.JFrame {

    List<Roteador> roteadores;
    int idLinks = 0;

    public View() {
        initComponents();
        this.roteadores = new ArrayList<>();
        this.setVisible(true);
    }

    public List<Roteador> getRoteadores() {
        return roteadores;
    }

    public void verificaConexao() {
        String s = "";
        for (int i = 0; i < roteadores.size(); i++) {
            for (int j = 0; j < roteadores.get(i).getLinks().size(); j++) {
                Link l = roteadores.get(i).getLinks().get(j);
                if (l.getDistancia() != 0) {
                    s += "Roteador " + l.getR1().getIdRoteador() + ": " + mergeIp(l.getIp1()) + "\n";
                    s += "Mascara: " + mergeIp(l.getMascara1()) + "\n";
                    s += "Roteador " + l.getR2().getIdRoteador() + ": " + mergeIp(l.getIp2()) + "\n";
                    s += "Mascara: " + mergeIp(l.getMascara2()) + "\n";

                    int resul1 = l.getIp1() & l.getMascara1();
                    int resul2 = l.getIp2() & l.getMascara2();

                    if (l.getIp1() == l.getIp2() || resul1 != resul2) {
                        s += "Link configurado incorretamente. \n";
                    }

                    s += "\n";
                }
            }
        }
        jTextArea.setText(s);
    }

    public String mergeIp(int ip) {
        String s = "";
        s += getA1(ip) + ".";
        s += getA2(ip) + ".";
        s += getA3(ip) + ".";
        s += getA4(ip);
        return s;
    }

    public void newLink(Roteador r1, int ip1, int mascara1, Roteador r2, int ip2, int mascara2, int distancia) {
        if (r1.getIdRoteador() == r2.getIdRoteador()) {
            JOptionPane.showMessageDialog(null, "Roteadores iguais !!!");
            return;
        }

        for (int i = 0; i < roteadores.size(); i++) {
            if (roteadores.get(i).getIdRoteador() == r1.getIdRoteador() || roteadores.get(i).getIdRoteador() == r2.getIdRoteador()) {
                roteadores.get(i).newLink(r1, ip1, mascara1, r2, ip2, mascara2, distancia);
            }
        }

        idLinks++;
        JOptionPane.showMessageDialog(null, "Link criado");
    }

    public void newRoteador(int id) {
        roteadores.add(new Roteador(id));
    }

    public void atualizaCombo() {
        jCBRot1.removeAllItems();
        jCBRot2.removeAllItems();
        for (int i = 0; i < roteadores.size(); i++) {
            jCBRot1.addItem(roteadores.get(i).getIdRoteador());
            jCBRot2.addItem(roteadores.get(i).getIdRoteador());
        }

    }
    
    public void mostraTabela(){
        String s = "";
        
        for (int i = 0; i < roteadores.size(); i++) {
            for (int j = 0; j < roteadores.get(i).getMatriz().length; j++) {
                for (int k = 0; k < roteadores.get(i).getMatriz().length; k++) {
                    if (j == 0 && k == 0) {
                        s += "R" + roteadores.get(i).getMatriz()[j][k] + "\t";
                    } else {
                        if (roteadores.get(i).getMatriz()[j][k] == 99) {
                            s += "∞ \t";
                        } else {
                            s += roteadores.get(i).getMatriz()[j][k] + "\t";
                        }
                    }
                }
                s += "\n";
            }
            s += "\n";
        }

        jTextArea.setText(s);
    }

    private int getA4(int c) {
        return (c & 0xFF);
    }

    private int getA3(int c) {
        return ((c >> 8) & 0xFF);
    }

    private int getA2(int c) {
        return ((c >> 16) & 0xFF);
    }

    private int getA1(int c) {
        return ((c >> 24) & 0xFF);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLayeredPane1 = new javax.swing.JLayeredPane();
        jLabel4 = new javax.swing.JLabel();
        jBAdd1 = new javax.swing.JButton();
        jCBRot1 = new javax.swing.JComboBox();
        jCBRot2 = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTFIP1 = new javax.swing.JTextField();
        jTFIP2 = new javax.swing.JTextField();
        jTFMasc1 = new javax.swing.JTextField();
        jTFMasc2 = new javax.swing.JTextField();
        jTFDist = new javax.swing.JTextField();
        jLayeredPane2 = new javax.swing.JLayeredPane();
        jBRemover2 = new javax.swing.JButton();
        jBAdd2 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jTFID = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea = new javax.swing.JTextArea();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Distance Between Routers");
        setResizable(false);

        jLayeredPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("Link"));

        jLabel4.setText("Distância");

        jBAdd1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/redes/icons/add.png"))); // NOI18N
        jBAdd1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAdd1ActionPerformed(evt);
            }
        });

        jLabel1.setText("IP");

        jLabel2.setText("Roteador");

        jLabel3.setText("Máscara");

        jTFIP1.setText("192.168.1.1");

        jTFIP2.setText("192.168.1.2");

        jTFMasc1.setText("255.255.255.0");

        jTFMasc2.setText("255.255.255.0");

        javax.swing.GroupLayout jLayeredPane1Layout = new javax.swing.GroupLayout(jLayeredPane1);
        jLayeredPane1.setLayout(jLayeredPane1Layout);
        jLayeredPane1Layout.setHorizontalGroup(
            jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jLayeredPane1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jLayeredPane1Layout.createSequentialGroup()
                        .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jLayeredPane1Layout.createSequentialGroup()
                                .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jCBRot1, 0, 102, Short.MAX_VALUE)
                                    .addComponent(jTFIP1)
                                    .addComponent(jTFMasc1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jCBRot2, 0, 102, Short.MAX_VALUE)
                                    .addComponent(jTFIP2)
                                    .addComponent(jTFMasc2)))
                            .addComponent(jTFDist)))
                    .addComponent(jBAdd1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jLayeredPane1Layout.setVerticalGroup(
            jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jLayeredPane1Layout.createSequentialGroup()
                .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTFIP1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTFIP2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTFMasc1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTFMasc2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTFDist, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCBRot1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCBRot2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jBAdd1))
        );
        jLayeredPane1.setLayer(jLabel4, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jBAdd1, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jCBRot1, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jCBRot2, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jTFIP1, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jTFIP2, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jTFMasc1, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jTFMasc2, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jTFDist, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLayeredPane2.setBorder(javax.swing.BorderFactory.createTitledBorder("Roteador"));

        jBRemover2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/redes/icons/cross.png"))); // NOI18N
        jBRemover2.setText("Remover");
        jBRemover2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBRemover2ActionPerformed(evt);
            }
        });

        jBAdd2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/redes/icons/add.png"))); // NOI18N
        jBAdd2.setText("Adicionar");
        jBAdd2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAdd2ActionPerformed(evt);
            }
        });

        jLabel5.setText("ID");

        javax.swing.GroupLayout jLayeredPane2Layout = new javax.swing.GroupLayout(jLayeredPane2);
        jLayeredPane2.setLayout(jLayeredPane2Layout);
        jLayeredPane2Layout.setHorizontalGroup(
            jLayeredPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jLayeredPane2Layout.createSequentialGroup()
                .addGroup(jLayeredPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jLayeredPane2Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jBAdd2)
                        .addGap(18, 18, 18)
                        .addComponent(jBRemover2))
                    .addGroup(jLayeredPane2Layout.createSequentialGroup()
                        .addContainerGap(42, Short.MAX_VALUE)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTFID, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jLayeredPane2Layout.setVerticalGroup(
            jLayeredPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jLayeredPane2Layout.createSequentialGroup()
                .addGap(0, 11, Short.MAX_VALUE)
                .addGroup(jLayeredPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTFID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jLayeredPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBAdd2)
                    .addComponent(jBRemover2))
                .addContainerGap())
        );
        jLayeredPane2.setLayer(jBRemover2, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane2.setLayer(jBAdd2, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane2.setLayer(jLabel5, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane2.setLayer(jTFID, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel6.setFont(new java.awt.Font("Vani", 0, 18)); // NOI18N
        jLabel6.setText("Distance Between Routers");

        jTextArea.setEditable(false);
        jTextArea.setColumns(20);
        jTextArea.setRows(5);
        jScrollPane1.setViewportView(jTextArea);

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");

        jMenuItem1.setText("Verificar Conexões");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem1);

        jMenuItem2.setText("Mostra");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem2);

        jMenuItem3.setText("Executa");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem3);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane1)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        setSize(new java.awt.Dimension(752, 378));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void jBAdd2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAdd2ActionPerformed
        if (jTFID.getText().length() != 0) {
            for (int i = 0; i < roteadores.size(); i++) {
                if (roteadores.get(i).getIdRoteador() == Integer.parseInt(jTFID.getText())) {
                    JOptionPane.showMessageDialog(null, "Este ID já está cadastrado");
                    return;
                }
            }
            newRoteador(Integer.parseInt(jTFID.getText()));
            atualizaCombo();
            JOptionPane.showMessageDialog(null, "Roteador cadastrado");
            jTFID.setText("");
        }
    }//GEN-LAST:event_jBAdd2ActionPerformed

    private void jBAdd1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAdd1ActionPerformed
        if (jTFIP1.getText().length() != 0 && jTFIP2.getText().length() != 0 && jTFMasc1.getText().length() != 0
                && jTFMasc2.getText().length() != 0 && jTFDist.getText().length() != 0
                && roteadores.size() > 1) {
            Cast c = new Cast();
            c.setIp(jTFIP1.getText());
            int IP1 = c.getIp();

            c.setIp(jTFIP2.getText());
            int IP2 = c.getIp();

            c.setIp(jTFMasc1.getText());
            int Masc1 = c.getIp();

            c.setIp(jTFMasc2.getText());
            int Masc2 = c.getIp();

            int Dist = Integer.parseInt(jTFDist.getText());

            Roteador r1 = null;
            Roteador r2 = null;
            for (int i = 0; i < roteadores.size(); i++) {
                if (roteadores.get(i).getIdRoteador() == (int) jCBRot1.getSelectedItem()) {
                    r1 = roteadores.get(i);
                }

                if (roteadores.get(i).getIdRoteador() == (int) jCBRot2.getSelectedItem()) {
                    r2 = roteadores.get(i);
                }
            }

            newLink(r1, IP1, Masc1, r2, IP2, Masc2, Dist);
        }
    }//GEN-LAST:event_jBAdd1ActionPerformed

    private void jBRemover1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBRemover1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jBRemover1ActionPerformed

    private void jBRemover2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBRemover2ActionPerformed
        boolean existe = false;
        if (jTFID.getText().length() != 0) {
            for (int i = 0; i < roteadores.size(); i++) {
                if (roteadores.get(i).getIdRoteador() == Integer.parseInt(jTFID.getText())) {
                    roteadores.remove(i);
                    atualizaCombo();
                    existe = true;
                }
            }
            if (existe) {
                for (int i = 0; i < roteadores.size(); i++) {
                    Roteador r = roteadores.get(i);
                    for (int j = 0; j < r.getLinks().size(); j++) {
                        if (r.getLinks().get(j).getR1().getIdRoteador() == Integer.parseInt(jTFID.getText())) {
                            r.getLinks().remove(j);
                        } else {
                            if (r.getLinks().get(j).getR2().getIdRoteador() == Integer.parseInt(jTFID.getText())) {
                                r.getLinks().remove(j);
                            }
                        }
                    }
                }
                JOptionPane.showMessageDialog(null, "Roteador Removido");
            }
            if (!existe) {
                JOptionPane.showMessageDialog(null, "Este ID não existe!");
            }
        }
    }//GEN-LAST:event_jBRemover2ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        this.verificaConexao();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        mostraTabela();
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
//        roteadores.get(0).montarTabela(this);
//        roteadores.get(0).montarMsg();
        
       for (int i = 0; i < roteadores.size(); i++) {
            roteadores.get(i).montarTabela(this);
            roteadores.get(i).start();
       }
//       roteadores.get(0).montarMsg();
//       roteadores.get(0).receberMsg(roteadores.get(0).envio);;
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;

                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(View.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(View.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(View.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(View.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new View().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAdd1;
    private javax.swing.JButton jBAdd2;
    private javax.swing.JButton jBRemover2;
    private javax.swing.JComboBox jCBRot1;
    private javax.swing.JComboBox jCBRot2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JLayeredPane jLayeredPane2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTFDist;
    private javax.swing.JTextField jTFID;
    private javax.swing.JTextField jTFIP1;
    private javax.swing.JTextField jTFIP2;
    private javax.swing.JTextField jTFMasc1;
    private javax.swing.JTextField jTFMasc2;
    private javax.swing.JTextArea jTextArea;
    // End of variables declaration//GEN-END:variables
}
